//
//  WebSharePopVC.m
//  lishuaPro
//
//  Created by Jack Luo on 2018/11/5.
//  Copyright © 2018 嘉联支付有限公司. All rights reserved.
//

#import "WebSharePopVC.h"
#import <Masonry.h>

@interface WebSharePopVC ()

@property (nonatomic, copy) NSString *shareTitle;
@property (nonatomic, copy) NSString *shareContent;
@property (nonatomic, copy) NSString *shareURLStr;
@property (nonatomic, copy) UIImage  *shareImage;

@property (nonatomic, copy) UIImage  *shareThumbImage;

@end

@implementation WebSharePopVC

+ (instancetype)buildWebSharePopVCWithTitle:(NSString *)title
                                    content:(NSString *)content
                                      image:(UIImage *)image
                                     urlStr:(NSString *)str{
    
    WebSharePopVC *popVC = [[WebSharePopVC alloc] init];
    popVC.shareTitle = title;
    popVC.shareContent = content;
    popVC.shareURLStr  = str;
    popVC.shareImage   = image;
    
    return popVC;
}

- (id)init{
    self = [super init];
    if (self) {
        
        self.viewHeight = 150;
        
        [self setupUI];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark -
- (void)setupUI{
    
    UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
    btnCancel.backgroundColor = [UIColor whiteColor];
    [btnCancel setTitleColor:[UIColor colorWithRed:170/255.0 green:170/255.0 blue:170/255.0 alpha:1.0] forState:UIControlStateNormal];
    [btnCancel setTitle:@"取消" forState:UIControlStateNormal];
    [btnCancel addTarget:self action:@selector(btnCancelClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnCancel];
    
    [btnCancel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.equalTo(@50);
    }];
    
    UIView *platBgView = [[UIView alloc] init];
    platBgView.backgroundColor = [UIColor colorWithRed:250.0/255.0 green:250.0/255.0 blue:250.0/255.0 alpha:1.0];
    [self.view addSubview:platBgView];
    
    [platBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.bottom.equalTo(btnCancel.mas_top);
    }];
    
    [self addThirdPlatformInView:platBgView];
}

//添加第三方登录按钮
- (void)addThirdPlatformInView:(UIView *)aView{
    
    
    NSInteger count = 3;
    
    if (count > 0) {
        
        CGSize imageSize = CGSizeMake(44, 60);
        CGFloat iconDis  = fabs(([UIScreen mainScreen].bounds.size.width-imageSize.width*count)/(count));
        
        for (NSInteger i = 0; i < count; i++) {
            
            NSDictionary *platDict = [self platformDictWithIndex:i];
            UIImage *image = platDict[@"image"];
            NSString *text = platDict[@"text"];
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = CGRectMake(0, 0, 60, 60);
            button.tag = 100+i;
            button.backgroundColor = [UIColor grayColor];
            button.titleLabel.font = [UIFont systemFontOfSize:12];
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [button setTitle:text forState:UIControlStateNormal];
            [button setImage:image forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonPlatformClicked:) forControlEvents:UIControlEventTouchUpInside];
            [aView addSubview:button];
            
            CGSize imageSize = button.imageView.frame.size;
            CGSize titleSize = button.titleLabel.frame.size;
            
            button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
            [button setTitleEdgeInsets:UIEdgeInsetsMake(0 ,-imageSize.width, -imageSize.height - 5,0.0)];
            [button setImageEdgeInsets:UIEdgeInsetsMake(-titleSize.height - 5, 0.0,0.0, -titleSize.width)];
            
            [button mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(CGSizeMake(44, 60));
                make.centerY.offset(8);
                make.left.offset(iconDis/2.0+(imageSize.width+iconDis)*i);
            }];
        }
    }
}

- (NSDictionary *)platformDictWithIndex:(NSInteger)index{
    
    UIImage *image = nil;
    NSString *text = nil;
    
    if (index == 0) {
        
        image = [UIImage imageNamed:@"yqhy_icon_we chat"];
        text  = @"微信";
    }
    else if (index == 1){
        
        image = [UIImage imageNamed:@"yqhy_icon_moment"];
        text  = @"朋友圈";
    }
    else if (index == 2){
        
        image = [UIImage imageNamed:@"yqhy_icon_qq"];
        text  = @"QQ";
    }
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"image"] = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    dict[@"text"]  = text;
    
    return dict.copy;
}


#pragma mark -
- (void)btnCancelClicked:(UIButton *)button{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)buttonPlatformClicked:(UIButton *)button{
    
    

    
    [self dismissViewControllerAnimated:YES completion:nil];
}


@end
